using System.Math;
using Oyster.Math;

class Task080 : TaskBase
{
  override public SolveInt() : int
  {
    def sum100(s, i, c : IntX, p : IntX)
    {
      | _ when i == 100 => s
      | _ =>
        def p20 = p * 20;
        
        mutable x = 1;
        while ((p20 + x) * x <= c) x++;
        x--;
        
        sum100(s + x, i + 1, (c - (p20 + x) * x) * 100, p * 10 + x)
    }
    def sumAll(s, n : int)
    {
      | (_, 100) => s
      | _ =>
        def sqrt = Sqrt(n);
        sumAll(
          s + if (sqrt - Floor(sqrt) < 0.0000001) 0 else sum100(0, 0, IntX(n), IntX(0)),
          n + 1)
    }

    sumAll(0, 2)
  }
}
